package cn.stylefeng.guns.modular.gridsystem.timer;

import cn.stylefeng.guns.core.context.constant.ConstantContextHolder;
import cn.stylefeng.guns.core.timer.TimerTaskRunner;
import cn.stylefeng.guns.modular.gridsystem.constants.UplaodFolderConstant;
import cn.stylefeng.guns.modular.gridsystem.utils.MyFileUtils;
import org.springframework.stereotype.Component;

/**
 * 根据百分比删除指定目录的文件
 */
@Component
public class AutoDeleteFileByPercentumTaskRunner implements TimerTaskRunner {

    @Override
    public void action() {
        double diskThreshold = ConstantContextHolder.getDiskThreshold(); // 硬盘占用阈值
        String homePath = ConstantContextHolder.getFileHomePath(); // 计算百分百的目录
        double deleteFileRatio = ConstantContextHolder.getDeleteFileRatio(); // 删除文件占比
        //网关样本文件目录
        String directoryPath = MyFileUtils.getUploadPath() + "/" + UplaodFolderConstant.GATEWAY_SAMPLE_AUDIO_FOLDER;
        MyFileUtils.cleanupFilesByPercentum(homePath,directoryPath, diskThreshold,deleteFileRatio);
        //故障文件目录
        String directoryPath1 = MyFileUtils.getUploadPath() + "/" + UplaodFolderConstant.FAILURE_AUDIO_FOLDER;
        MyFileUtils.cleanupFilesByPercentum(homePath,directoryPath1, diskThreshold,deleteFileRatio);
    }

}
